package com.doge.calcalbum.core

import android.content.pm.ActivityInfo
import android.os.Bundle
import android.view.WindowManager
import androidx.fragment.app.FragmentActivity
import com.doge.calcalbum.utils.Activities
import com.doge.calcalbum.utils.closeKeyBoard
import com.doge.calcalbum.utils.useTranslucentStatusBar

open class BaseActivity : FragmentActivity() {
    open val statusBarLightMode: Boolean = true
    open val portraitOrientation: Boolean = true

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (portraitOrientation) requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
        useTranslucentStatusBar(statusBarLightMode)
        Activities.add(this)
    }

    override fun onResume() {
        super.onResume()
        window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
    }

    override fun onPause() {
        super.onPause()
        window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
    }

    override fun onDestroy() {
        super.onDestroy()
        Activities.remove(this)
    }

    override fun finish() {
        super.finish()
        closeKeyBoard()
    }
}